Skip to content

fix: use correct 'score' field for relevance filtering in retrieve_customer_context#415

Merged
notgitika merged 4 commits intoaws:mainfrom
biascia:fix/retrieve-customer-context-relevance-score-field
Apr 21, 2026
Merged

fix: use correct 'score' field for relevance filtering in retrieve_customer_context#415
notgitika merged 4 commits intoaws:mainfrom
biascia:fix/retrieve-customer-context-relevance-score-field

Conversation

@biascia
Copy link
Copy Markdown
Contributor

@biascia biascia commented Apr 14, 2026

Summary

AgentCoreMemorySessionManager.retrieve_customer_context filters retrieved memories using
m.get("relevanceScore", ...), but the MemoryRecordSummary shape returned by
retrieve_memory_records defines the field as score (confirmed via the AWS service model).

The field name mismatch means the fallback value is always used — set to
retrieval_config.relevance_score itself — so the condition relevance_score >= relevance_score
is always True. Every memory passes the filter regardless of the configured threshold.

Root cause

# Before — "relevanceScore" is never present; fallback makes condition always True
memories = [
    m for m in memories
    if m.get("relevanceScore", retrieval_config.relevance_score) >=
    retrieval_config.relevance_score
]

The MemoryRecordSummary boto3 service model shape:

score: Double   ← actual field name

Fix

# After — filter on the correct field; 0.0 default excludes records without a score
memories = [m for m in memories if m.get("score", 0.0) >= retrieval_config.relevance_score]

Using 0.0 as the default ensures records without a score are excluded rather than silently
passed through.

Changes

  • session_manager.py: fix field name in relevance filter
  • test_agentcore_memory_session_manager.py: update mock memory records to use "score" to
    match the actual API response shape

@biascia biascia requested a review from a team April 14, 2026 16:00
@biascia biascia force-pushed the fix/retrieve-customer-context-relevance-score-field branch from 929bcec to ba6a3b4 Compare April 14, 2026 16:06
@biascia biascia force-pushed the fix/retrieve-customer-context-relevance-score-field branch from ba6a3b4 to 9a2536a Compare April 14, 2026 16:08
@biascia biascia force-pushed the fix/retrieve-customer-context-relevance-score-field branch from 9a2536a to b13e514 Compare April 15, 2026 07:26
@biascia biascia force-pushed the fix/retrieve-customer-context-relevance-score-field branch from b13e514 to 6d97db1 Compare April 15, 2026 07:27
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@667ef55). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #415   +/-   ##
=======================================
  Coverage        ?   91.17%           
=======================================
  Files           ?       58           
  Lines           ?     5018           
  Branches        ?      765           
=======================================
  Hits            ?     4575           
  Misses          ?      252           
  Partials        ?      191           
Flag Coverage Δ
unittests 91.17% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@notgitika notgitika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding this

@notgitika notgitika merged commit e632e9d into aws:main Apr 21, 2026
21 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants